﻿using Dez;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class myInfo : System.Web.UI.Page
{
    DEZ dez = new DEZ();
    //todo сделать изменение пароля в Popup Control - Modal Window
    //http://demos.devexpress.com/ASPxperienceDemos/PopupControl/ModalWindow.aspx
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        LoadInfoData();
    }

    private void LoadInfoData()
    {
        var query = (from p in dez.PIPLE
                     where p.CODE == Profile.UserInfo.PeopleCode
                     select p).First();
        ed_passNO.Value = query.DISP_PSWD;
        ed_loginDisp.Value = query.DISP_LOGIN;
        ed_fio.Value = String.Format("{0} {1} {2}", query.F, query.I, query.O);
        ed_passSK.Value = query.PSWD;
        //
        var kontrQuery = from w in dez.WORKER
                         where w.PIPLE == Profile.UserInfo.PeopleCode
                         join p in dez.PIPLE on w.PIPLE equals p.CODE
                         join k in dez.KONTRAGENT on w.KONTRAGENT equals k.CODE
                         select new { w.KONTRAGENT, k.NAME};
        lst_kontr.Items.Clear();
        foreach (var item in kontrQuery)
        {
            lst_kontr.Items.Add(item.NAME, item.KONTRAGENT);
        }
    }

    protected void ASPxButton1_Click(object sender, EventArgs e)
    {
        ChangePassword();
    }

    private void ChangePassword()
    {
       var query = (from p in dez.PIPLE
                     where p.CODE == Profile.UserInfo.PeopleCode
                     select p).First();
       query.DISP_PSWD = ed_passNO.Text;
        dez.SaveChanges();
        LoadInfoData();
    }
    protected void btn_SaveSK_Click(object sender, EventArgs e)
    {
        var query = (from p in dez.PIPLE
                     where p.CODE == Profile.UserInfo.PeopleCode
                     select p).First();
        query.PSWD = ed_passSK.Text;
        dez.SaveChanges();
        LoadInfoData();
    }
}